package Client_logic;

/**
 * This class controls the Categories of all Products  
 * @author ameer
 * @author waleed
 * @author bshara
 * @author kamil
 */
public class Category{
	
	/** Category ID */
	private int CategoryID;
	
	/** Category Name */
	private String CategoryName;
	
	public Category(){
		this.CategoryID = 0;
		this.CategoryName = null;
	}
	
	/**
	 * @param CategoryID category ID
	 * @param CategoryName category name
	 */
	public Category(int CategoryID, String CategoryName){
		this.CategoryID = CategoryID;
		this.CategoryName = CategoryName;
	}
	
	/**
	 * @return the category ID
	 */
	public int GetCategoryID(){
		return this.CategoryID;
	}
	
	/**
	 * @param CategoryID the category ID to set
	 */
	public void SetCategoryID(int CategoryID){
		this.CategoryID = CategoryID;
	}
	
	/**
	 * @return the category name
	 */
	public String GetCategoryName(){
		return this.CategoryName;
	}
	
	/**
	 * @param CategoryName the category name to set
	 */
	public void SetCategoryName(String CategoryName){
		this.CategoryName = CategoryName;
	}
	
	/**
	 * This function adds a Section to the DB
	 * @return true on success , false on error
	 * @throws ClientNotInitializesException
	 */
	public boolean addCategory() throws ClientNotInitializesException{		
		ConnectionToServer connectiontoserver = new ConnectionToServer();
		try{
			Object ServerMessage = connectiontoserver.addCategorySection(CategoryID, CategoryName);
			if (ServerMessage == null)
				return false;
			if (ServerMessage.equals("OK"))
				return true;
			return false;
		}
		catch(Exception e){
			return false;
		}				
	}
	
	/**
	 * This function updates the Section in the DB
	 * @return true on success , false on fail
	 * @throws ClientNotInitializesException
	 */
	public boolean updateCategory() throws ClientNotInitializesException{		
		ConnectionToServer connectiontoserver = new ConnectionToServer();
		try{
			Object ServerMessage = connectiontoserver.updateCategorySection(CategoryID, CategoryName);
			if (ServerMessage == null)
				return false;
			if (ServerMessage.equals("OK"))
				return true;
			return false;
		}
		catch(Exception e){
			return false;
		}				
	}
	
	/**
	 * This function removes the Section from DB
	 * @return true on success , false on fail
	 * @throws ClientNotInitializesException
	 */
	public boolean removeCategory() throws ClientNotInitializesException{		
		ConnectionToServer connectiontoserver = new ConnectionToServer();
		try{
			Object ServerMessage = connectiontoserver.removeCategorySection(CategoryID);
			if (ServerMessage == null)
				return false;
			if (ServerMessage.equals("OK"))
				return true;
			return false;
		}
		catch(Exception e){
			return false;
		}				
	}
	
	/**
	 * This function adds a Type to the Section
	 * @param typeID the type ID
	 * @return true on success , false on fail
	 * @throws ClientNotInitializesException
	 */
	public boolean addTypeToCategory(int typeID) throws ClientNotInitializesException{		
		ConnectionToServer connectiontoserver = new ConnectionToServer();
		try{
			Object ServerMessage = connectiontoserver.addTypeToSection(CategoryID, typeID);
			if (ServerMessage == null)
				return false;
			if (ServerMessage.equals("OK"))
				return true;
			return false;
		}
		catch(Exception e){
			return false;
		}				
	}
	
	/**
	 * This function removes a Type from the Section 
	 * @param typeID the type ID
	 * @return true on success , false on fail
	 * @throws ClientNotInitializesException
	 */
	public boolean removeTypeFromCategory(int typeID) throws ClientNotInitializesException{		
		ConnectionToServer connectiontoserver = new ConnectionToServer();
		try{
			Object ServerMessage = connectiontoserver.removeTypeFromSection(CategoryID, typeID);
			if (ServerMessage == null)
				return false;
			if (ServerMessage.equals("OK"))
				return true;
			return false;
		}
		catch(Exception e){
			return false;
		}				
	}
	
	/**
	 * This function loads all Types in the Section
	 * @return true on success , false on fail
	 * @throws ClientNotInitializesException
	 */
	public String[] GetAllCategoryTypes() throws ClientNotInitializesException{		
		ConnectionToServer connectiontoserver = new ConnectionToServer();
		try{
			Object ServerMessage = connectiontoserver.loadAllSectionType(CategoryID);
			if (ServerMessage == null)
				return null;
			return (String[])ServerMessage;
		}
		catch(Exception e){
			return null;
		}				
	}
}
